package cn.edu.cqut.test0511;

import java.util.Scanner;

/*
 * 1、让一个类继承自Thread
 * 2、让一个类实现接口Runnable
 */

public class Test1 {
	public static void main(String[] args) throws Exception {
		Cat cat = new Cat();
		Dog dog = new Dog();
		
		cat.start();
		dog.start();

		Scanner scanner = new Scanner(System.in);
		while(true)
		{
			String str = scanner.nextLine();
			if(str.equals("exit"))
				break;
			System.out.println(str);
		}
		scanner.close();
	}
}

class Cat extends Thread{
	@Override
	public void run() {
		for (;;) {
			speak();
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public void speak() {
		System.out.println("喵喵喵......");
	}
}

class Dog extends Thread {
	@Override
	public void run() {
		for (;;) {
			speak();
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public void speak() {
		System.out.println("汪汪汪......");
	}
}
